package com.chenhongjian.webapp.config;

/**
 * Created by a on 2018/3/26.
 */
public class BaseResponse<T> {
    public static final int ERROR = -1;
    public static final int SUCCESS = 0;
    private String message;
    private boolean success;
    private int code;
    private T data;

    public BaseResponse(){

    }


    public BaseResponse(String msg,boolean success,int code,T response){
        this.message = msg;
        this.success = success;
        this.code = code;
        this.data = response;
    }
    public static BaseResponse getDefatultError(String msg){
        if (msg == null || msg.length() ==0){
                msg = "request error";
        }
        return new BaseResponse(msg,false,ERROR,null);
    }

    public static BaseResponse getDefaultSuccess(String msg){
        if (msg == null || msg.length() ==0){
            msg = "request success";
        }
        return new BaseResponse(msg,true,SUCCESS,null);
    }
    public static BaseResponse getDefaultSuccess(String msg,Object object){
        if (msg == null || msg.length() ==0){
            msg = "request success";
        }
        return new BaseResponse(msg,true,SUCCESS,object);
    }
    public static BaseResponse getDefaultSuccess(Object object){
        return new BaseResponse("request success",true,SUCCESS,object);
    }
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
